﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace EF.Util
{
    public class CookieHelp
    {

        /// <summary>
        /// 创建cookie
        /// </summary>
        /// <param name="cookieName">cookie名字</param>
        /// <param name="cookieValue">cookie值</param>
        /// <param name="cookieTime">cookie有效时间</param>
        public static void CreateCookieValue(string cookieName, string cookieValue, DateTime cookieTime)
        {
            HttpCookie cookie = new HttpCookie(cookieValue); 
            cookie.Value = cookieValue;
            cookie.Expires = cookieTime;
            HttpContext.Current.Response.Cookies.Add(cookie);
        }

        /// <summary>
        /// 获取cookie
        /// </summary>
        /// <param name="cookieName">cookie名字</param>
        /// <returns></returns>
        public static string GetCookieValue(string cookieName) 
        { 
            string cookieValue = "";
            HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];
            if (cookie==null) 
            { 
                cookieValue = ""; 
            } 
            else 
            { 
                cookieValue = cookie.Value; 
            }

            return cookieValue;
       }
    }
}
